{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "convenient-wallace",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "lonely-liberal",
   "metadata": {},
   "source": [
    "# 题2：股票涨跌幅数据离散化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "stretch-rogers",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取数据\n",
    "df = pd.read_csv('data/stock.csv', usecols=['p_change'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "derived-clearing",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p_change</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-02-27</th>\n",
       "      <td>2.68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-26</th>\n",
       "      <td>3.02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-23</th>\n",
       "      <td>2.42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-22</th>\n",
       "      <td>1.64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-14</th>\n",
       "      <td>2.05</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            p_change\n",
       "2018-02-27      2.68\n",
       "2018-02-26      3.02\n",
       "2018-02-23      2.42\n",
       "2018-02-22      1.64\n",
       "2018-02-14      2.05"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "electoral-intervention",
   "metadata": {},
   "outputs": [],
   "source": [
    "p_change = df['p_change']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "local-wedding",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2018-02-27    2.68\n",
       "2018-02-26    3.02\n",
       "2018-02-23    2.42\n",
       "2018-02-22    1.64\n",
       "2018-02-14    2.05\n",
       "              ... \n",
       "2015-03-06    8.51\n",
       "2015-03-05    2.02\n",
       "2015-03-04    1.57\n",
       "2015-03-03    1.44\n",
       "2015-03-02    2.62\n",
       "Name: p_change, Length: 643, dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p_change"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "therapeutic-falls",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 自己指定分组区间\n",
    "bins = [-100, -7, -5, -3, 0, 3, 5, 7, 100]\n",
    "p_counts = pd.cut(p_change, bins)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "helpful-ghana",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2018-02-27      (0, 3]\n",
       "2018-02-26      (3, 5]\n",
       "2018-02-23      (0, 3]\n",
       "2018-02-22      (0, 3]\n",
       "2018-02-14      (0, 3]\n",
       "                ...   \n",
       "2015-03-06    (7, 100]\n",
       "2015-03-05      (0, 3]\n",
       "2015-03-04      (0, 3]\n",
       "2015-03-03      (0, 3]\n",
       "2015-03-02      (0, 3]\n",
       "Name: p_change, Length: 643, dtype: category\n",
       "Categories (8, interval[int64]): [(-100, -7] < (-7, -5] < (-5, -3] < (-3, 0] < (0, 3] < (3, 5] < (5, 7] < (7, 100]]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p_counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "vietnamese-heritage",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 得出one-hot编码矩阵\n",
    "dummies = pd.get_dummies(p_counts, prefix=\"rise\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "stylish-processor",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>rise_(-100, -7]</th>\n",
       "      <th>rise_(-7, -5]</th>\n",
       "      <th>rise_(-5, -3]</th>\n",
       "      <th>rise_(-3, 0]</th>\n",
       "      <th>rise_(0, 3]</th>\n",
       "      <th>rise_(3, 5]</th>\n",
       "      <th>rise_(5, 7]</th>\n",
       "      <th>rise_(7, 100]</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-02-27</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-26</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-23</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-22</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-14</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-06</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-05</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-04</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-03</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-02</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>643 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            rise_(-100, -7]  rise_(-7, -5]  rise_(-5, -3]  rise_(-3, 0]  \\\n",
       "2018-02-27                0              0              0             0   \n",
       "2018-02-26                0              0              0             0   \n",
       "2018-02-23                0              0              0             0   \n",
       "2018-02-22                0              0              0             0   \n",
       "2018-02-14                0              0              0             0   \n",
       "...                     ...            ...            ...           ...   \n",
       "2015-03-06                0              0              0             0   \n",
       "2015-03-05                0              0              0             0   \n",
       "2015-03-04                0              0              0             0   \n",
       "2015-03-03                0              0              0             0   \n",
       "2015-03-02                0              0              0             0   \n",
       "\n",
       "            rise_(0, 3]  rise_(3, 5]  rise_(5, 7]  rise_(7, 100]  \n",
       "2018-02-27            1            0            0              0  \n",
       "2018-02-26            0            1            0              0  \n",
       "2018-02-23            1            0            0              0  \n",
       "2018-02-22            1            0            0              0  \n",
       "2018-02-14            1            0            0              0  \n",
       "...                 ...          ...          ...            ...  \n",
       "2015-03-06            0            0            0              1  \n",
       "2015-03-05            1            0            0              0  \n",
       "2015-03-04            1            0            0              0  \n",
       "2015-03-03            1            0            0              0  \n",
       "2015-03-02            1            0            0              0  \n",
       "\n",
       "[643 rows x 8 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dummies"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acknowledged-analysis",
   "metadata": {},
   "source": [
    "# 题3：分别使用交叉表计算星期与股票涨跌幅的关系"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "formed-event",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取数据\n",
    "df = pd.read_csv('data/stock.csv',usecols=['open','close','p_change'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "little-barrier",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 按照索引日期排序\n",
    "df = df.sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "personal-south",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1、先把对应的日期找到星期几\n",
    "date = pd.to_datetime(df.index).weekday\n",
    "df['week'] = date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "mounted-burton",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>p_change</th>\n",
       "      <th>week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-03-02</th>\n",
       "      <td>12.25</td>\n",
       "      <td>12.52</td>\n",
       "      <td>2.62</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-03</th>\n",
       "      <td>12.52</td>\n",
       "      <td>12.70</td>\n",
       "      <td>1.44</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-04</th>\n",
       "      <td>12.80</td>\n",
       "      <td>12.90</td>\n",
       "      <td>1.57</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-05</th>\n",
       "      <td>12.88</td>\n",
       "      <td>13.16</td>\n",
       "      <td>2.02</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-06</th>\n",
       "      <td>13.17</td>\n",
       "      <td>14.28</td>\n",
       "      <td>8.51</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open  close  p_change  week\n",
       "2015-03-02  12.25  12.52      2.62     0\n",
       "2015-03-03  12.52  12.70      1.44     1\n",
       "2015-03-04  12.80  12.90      1.57     2\n",
       "2015-03-05  12.88  13.16      2.02     3\n",
       "2015-03-06  13.17  14.28      8.51     4"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "other-public",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2、假如把p_change按照大小去分个类0为界限\n",
    "df['posi_neg'] = np.where(df['p_change'] > 0, 1, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "enhanced-pound",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>p_change</th>\n",
       "      <th>week</th>\n",
       "      <th>posi_neg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-03-02</th>\n",
       "      <td>12.25</td>\n",
       "      <td>12.52</td>\n",
       "      <td>2.62</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-03</th>\n",
       "      <td>12.52</td>\n",
       "      <td>12.70</td>\n",
       "      <td>1.44</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-04</th>\n",
       "      <td>12.80</td>\n",
       "      <td>12.90</td>\n",
       "      <td>1.57</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-05</th>\n",
       "      <td>12.88</td>\n",
       "      <td>13.16</td>\n",
       "      <td>2.02</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-06</th>\n",
       "      <td>13.17</td>\n",
       "      <td>14.28</td>\n",
       "      <td>8.51</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open  close  p_change  week  posi_neg\n",
       "2015-03-02  12.25  12.52      2.62     0         1\n",
       "2015-03-03  12.52  12.70      1.44     1         1\n",
       "2015-03-04  12.80  12.90      1.57     2         1\n",
       "2015-03-05  12.88  13.16      2.02     3         1\n",
       "2015-03-06  13.17  14.28      8.51     4         1"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "supported-intelligence",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 通过交叉表找寻两列数据的关系\n",
    "count = pd.crosstab(df['week'], df['posi_neg'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "standing-pilot",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>posi_neg</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>week</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>63</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>55</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>61</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>63</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>59</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "posi_neg   0   1\n",
       "week            \n",
       "0         63  62\n",
       "1         55  76\n",
       "2         61  71\n",
       "3         63  65\n",
       "4         59  68"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "annual-plymouth",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 算数运算，先求和\n",
    "sum = count.sum(axis=1).astype(np.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "documentary-address",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "week\n",
       "0    125.0\n",
       "1    131.0\n",
       "2    132.0\n",
       "3    128.0\n",
       "4    127.0\n",
       "dtype: float32"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "standard-surrey",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 进行相除操作，得出比例\n",
    "pro = count.div(sum, axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "fantastic-majority",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>posi_neg</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>week</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.504000</td>\n",
       "      <td>0.496000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.419847</td>\n",
       "      <td>0.580153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.462121</td>\n",
       "      <td>0.537879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.492188</td>\n",
       "      <td>0.507812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.464567</td>\n",
       "      <td>0.535433</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "posi_neg         0         1\n",
       "week                        \n",
       "0         0.504000  0.496000\n",
       "1         0.419847  0.580153\n",
       "2         0.462121  0.537879\n",
       "3         0.492188  0.507812\n",
       "4         0.464567  0.535433"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pro"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "seasonal-buying",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEDCAYAAAAlRP8qAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAToElEQVR4nO3de5hdVXnH8e9LLkYlxgpTkUzCpCVchku5DBEarVBAQpomVS4mXhBBUx6gpQWpWC9FvBR7gaqNShQvRCWGiJpHRtFGUKABEkApJI1EEskERRwBixhy4e0f50COwyRzkjkzJ1nz/TxPHs5ee5293rMf5pedddbeE5mJJGnXt1uzC5AkNYaBLkmFMNAlqRAGuiQVwkCXpEIY6JJUiOHNGnjPPffMtra2Zg0vSbuku+6661eZ2dLbvqYFeltbG8uWLWvW8JK0S4qIn21tn1MuklQIA12SCmGgS1IhmjaHLkmNtnHjRrq6uli/fn2zS+m3UaNG0drayogRI+p+j4EuqRhdXV2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Z4GkEujXUl2SnZk/aF51WzeUplyeAfYGftaj/RXVfUNKRNy7tV3Aywezlibb7dlplsxcExHHAgsjYh8q52Io2ZSZm4GnIuKnmfkbgMz8XUQMtZ+RDuAC4D3AxZn5o4j43c4a5M8aSoH+d8DiiHgAWFttGw/sC5y/tTcV7OXAScBjPdoD+O/BL6dpHomIwzLzRwDVK/VpwOeAQ5pa2eDbEBEvysyngCOfbYyIMQyxi57MfAa4MiKuq/73EXaBvNzpC2yUzPxOROxH5XHAtV+KLq1elQw13wJ2fzbIakXEzYNeTfOcAWyqbcjMTcAZEXFVc0pqmj/LzKfhuUB71gi2PNpjSKk+Qfa0iPgL4DfNrqcvQ2YOXZJK5zp0SSqEgS5JhTDQpe0UETdHxE79iw40NBnoklQIA13Fi4iLq3eEEhFXRsT3q6//PCK+HBGvjYglEXF3RFwXEbtX9x8ZET+IiLsi4saIeEWP4+4WEV+IiA8N/qeSns9A11BwC/Dq6usOYPeIGFFtuxd4L3BC9Tb/ZcCF1f2fAE7NzCOprEuvvfV9OPBl4IHMfO/gfAxp24bMOnQNaXcBR0bES4CngbupBPurqfz6xHbgtogAGAksAfYHDga+V20fBvy85phXAQuG0vNNtPMz0FW8zNwYEauBM6ncBXsvlQct7QusBr6XmbNq3xMRh1B5xs8xWznsfwPHRcS/Z+b6ASte2g5OuWiouAV4J/DD6utzgHuA24HJEbEvQES8uHpH8UqgJSKOqbaPiIiDao53NdAJLIgIL4y0UzDQNVTcQuVBbEsy8xFgPXBLZj5K5cr92uoDy5YAB2TmBuBU4KMR8WPgR8Cf1h4wM6+g8pfCvIjwZ0lN563/klQIryokqRAGuiQVwkCXpEIY6JJUCANdkgphoEtSIQx0SSqEgS5Jhfh/TFJIfR0T37gAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画图查看\n",
    "pro.plot(kind='bar', stacked=True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "attempted-radical",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>p_change</th>\n",
       "      <th>week</th>\n",
       "      <th>posi_neg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-03-02</th>\n",
       "      <td>12.25</td>\n",
       "      <td>12.52</td>\n",
       "      <td>2.62</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-03</th>\n",
       "      <td>12.52</td>\n",
       "      <td>12.70</td>\n",
       "      <td>1.44</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-04</th>\n",
       "      <td>12.80</td>\n",
       "      <td>12.90</td>\n",
       "      <td>1.57</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-05</th>\n",
       "      <td>12.88</td>\n",
       "      <td>13.16</td>\n",
       "      <td>2.02</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-06</th>\n",
       "      <td>13.17</td>\n",
       "      <td>14.28</td>\n",
       "      <td>8.51</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open  close  p_change  week  posi_neg\n",
       "2015-03-02  12.25  12.52      2.62     0         1\n",
       "2015-03-03  12.52  12.70      1.44     1         1\n",
       "2015-03-04  12.80  12.90      1.57     2         1\n",
       "2015-03-05  12.88  13.16      2.02     3         1\n",
       "2015-03-06  13.17  14.28      8.51     4         1"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "massive-housing",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 通过透视表，将整个过程变成更简单一些\n",
    "df1 = df.pivot_table(['posi_neg'], index='week')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "inappropriate-egypt",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>posi_neg</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>week</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.496000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.580153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.537879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.507812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.535433</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      posi_neg\n",
       "week          \n",
       "0     0.496000\n",
       "1     0.580153\n",
       "2     0.537879\n",
       "3     0.507812\n",
       "4     0.535433"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "attractive-wyoming",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEDCAYAAAAlRP8qAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAATL0lEQVR4nO3df7BfdZ3f8eeLJJC6YJyBdLFJMLGEH9mF4cclSDO7AhUNyJCOhA6oFQRLGcgsHSsDziJV2s7oavFXMxgEt8AsAjJoUzfd6ERZkY2SgFkwpIEsZOEyrRsD1mHYEK68+8f9xlwvN7nfhG/uDZ/7fMwwnPM5n3vO+3vm5pWTzzmf801VIUl68ztgvAuQJPWGgS5JjTDQJakRBrokNcJAl6RGGOiS1IjJ3XRKshD4MjAJuLWqPjtCn38NfBoo4G+r6oO72+dhhx1Ws2fP3tN6JWlCe+SRR35ZVdNH2jZqoCeZBCwFzgL6gTVJllfVE0P6zAU+CSyoqheT/NPR9jt79mzWrl3b7WeQJAFJ/n5X27oZcpkPbKqqp6tqO3A3sGhYn38LLK2qFwGq6h/2tlhJ0t7pJtBnAM8NWe/vtA11FHBUkoeS/KQzRPM6SS5PsjbJ2i1btuxdxZKkEfXqpuhkYC5wOnAR8PUkbxveqapuqaq+quqbPn3EISBJ0l7q5qbo88CsIeszO21D9QM/rapXgWeSPMlgwK/pSZWS3pReffVV+vv72bZt23iX8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PocuSY0w0CWpEQa6tIeSPJBkv/7mGk1MBrokNcJAV/OSXNOZEUqSLyb5QWf5zCR/keS9SVYneTTJt5Ic3Nl+cpK/TvJIkpVJ3j5svwck+e9J/vPYfyrp9Qx0TQQPAn/UWe4DDk4ypdP2GHA98J7ONP+1wMc7278KLK6qkxl8Ln3o1PfJwF8AT1XV9WPzMaTdmzDPoWtCewQ4OclbgVeARxkM9j9i8Ptw5wEPJQE4EFgNHA38IfD9Tvsk4P8M2ecy4N6J9H4T7f8MdDWvql5N8gxwCYOzYB9j8EVLRwLPAN+vqouG/kyS4xh8x89pu9jt3wBnJPmvVbVtnxUv7QGHXDRRPAh8AvhRZ/kK4GfAT4AFSY4ESPJ7nRnFG4HpSU7rtE9J8gdD9ncbsAK4N4kXRtovGOiaKB5k8EVsq6vqF8A24MGq2sLglfs3Oy8sWw0cU1XbgcXA55L8LbAO+BdDd1hVNzH4l8KdSfyzpHHn1H9JaoRXFZLUCANdkhphoEtSIwx0SWqEgS5JjTDQJakRBrokNeL/AxNxTsGxCZBSAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画图查看\n",
    "df1.plot(kind='bar', stacked=True)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "responsible-calcium",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "serial-consumption",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "silver-brighton",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  },
  "nbTranslate": {
   "displayLangs": [
    "*"
   ],
   "hotkey": "alt-t",
   "langInMainMenu": true,
   "sourceLang": "en",
   "targetLang": "fr",
   "useGoogleTranslate": true
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
